package cpr.command;

import java.util.Collection;
import java.util.Iterator;

import cpr.CommandHandler;
import cpr.DefaultCommandHandler;
import cpr.Printer;

public class CmdHelp extends DefaultCommandHandler {
	private boolean control = false;
	public CmdHelp(boolean ctl) {
		super("help","this help",null,null);
		control = ctl;
	}
	public void execute(String[] params) {
		Collection handlers = getCommandContext().getCommandHandlers(control);
		for (Iterator iter = handlers.iterator(); iter.hasNext();) {
			CommandHandler handler = (CommandHandler) iter.next();
			String name = handler.getName();
			String help = handler.getQuickInfo();
			if (help==null ) {
				help = "";
			} else {
				help = ": "+help;
			}
			Printer.println(name+help );
		}
	}
}
